<template>
    <el-dialog title="编辑部门" :visible.sync="dialogFormVisible">
     <el-form ref="dataForm" :model="dept" label-width="120px">
        <el-form-item label="部门名称">
          <el-input v-model="dept.name" placeholder='请输入部门名称'></el-input>
        </el-form-item>
        <el-form-item label="部门编码">
          <el-input v-model="dept.code" placeholder='请输入部门编码'></el-input>
        </el-form-item>
        <el-form-item label="部门负责人">
          <el-input v-model="dept.manager" placeholder='请输入负责人'></el-input>
        </el-form-item>
        <el-form-item label="部门介绍">
          <el-input v-model="dept.introduce" placeholder='请输入介绍'></el-input>
        </el-form-item>
     </el-form>
     <div slot="footer" class="dialog-footer">
         <el-button type="primary" @click="saveDept">确定</el-button>
         <el-button @click="dialogFormVisible=false">取消</el-button>
     </div>
    </el-dialog>
</template>

<script>
import {saveOrUpdate} from '@/api/base/dept'
export default {
    data(){
        return{
            // 添加部门的模型
            parentId: '',
            dialogFormVisible: false, // 显示或隐藏弹窗，false为隐藏
            dept: {} // 新部门对象
        }
    },
    methods: {
        saveDept() {
            this.dept.parentId = this.parentId;
            saveOrUpdate(this.dept).then(res => {
                alert(res.data.message);
                if(res.data.success) {
                // 如果成功
                location.reload();
                this.dialogFormVisible = false;
                }
            })
        },
    }
}
</script>
